package org.dandelion.ruler;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import org.dandelion.R;

public class ResultActivity extends AppCompatActivity {

    private TextView showRecord;
    private Button clear;
    SharedPreferences sharedPreferences = null;
    SharedPreferences.Editor editor = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);

        showRecord = findViewById(R.id.showRecordText);
        clear = findViewById(R.id.clear);

        sharedPreferences = getSharedPreferences("len", MODE_PRIVATE);
        editor = sharedPreferences.edit();

        int count = sharedPreferences.getInt("count", 0);
        StringBuilder showingStr = new StringBuilder();

        for (int i = 1; i <= count; i++) {
            showingStr.append(sharedPreferences.getFloat("r" + i, 0)).append("\n");
        }

        showRecord.setText(showingStr.toString());

        clear.setOnClickListener(view -> {
            editor.clear();
            editor.putInt("count", 0);
            editor.apply();
            showRecord.setText("");
        });
    }
}